#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import os
from huggingface_hub import snapshot_download

def download_w2vbert_model():
    """使用国内镜像下载facebook/w2v-bert-2.0模型"""
    print("正在从国内镜像下载facebook/w2v-bert-2.0模型...")
    print("保存位置: ./models/w2v-bert-2.0/")
    
    # 设置国内镜像
    os.environ["HF_ENDPOINT"] = "https://hf-mirror.com"
    
    try:
        # 下载到models目录
        snapshot_download(
            repo_id="facebook/w2v-bert-2.0",
            local_dir="./models/w2v-bert-2.0",
            local_dir_use_symlinks=False,
            resume_download=True
        )
        print("✅ 模型下载完成！")
        print("📁 文件已保存到: ./models/w2v-bert-2.0/")
        
        # 检查文件
        model_path = "./models/w2v-bert-2.0"
        if os.path.exists(os.path.join(model_path, "config.json")):
            print("✅ config.json 文件正常")
        if os.path.exists(os.path.join(model_path, "preprocessor_config.json")):
            print("✅ preprocessor_config.json 文件正常")
        
        print("🎉 模型已准备好，可以启动IndexTTS2了！")
        
    except Exception as e:
        print(f"❌ 下载失败: {e}")
        print("💡 建议手动从 https://hf-mirror.com/facebook/w2v-bert-2.0 下载")

if __name__ == "__main__":
    download_w2vbert_model()
